package com.product.android.commonInterface.chat;

import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;

import com.nd.android.u.allcommon.R;
import com.product.android.business.ApplicationVariable;


public class SearchContract implements Parcelable {
	
	private long uapuid;
	private long fid;
	private long workid; //add by yanghq Fix Bug #40134
	private int fgid;
	private String deptid;
	private String classid;

	private String username;
	private String note;
	private String signature;
	private int sysavatar;
	
	private String mobilephone;
	private String telephone;
	
//	private long contactId;
//	private long photoId;
	private boolean isChecked;

	private boolean isFriend;
	
	public SearchContract(){}
	
	
	public boolean isFriend() {
		return isFriend;
	}

	public void setIsFriend(boolean isFriend){
		
		this.isFriend = isFriend;
	}
	public long getFid() {
		return fid;
	}
	public void setFid(long fid) {
		this.fid = fid;
	}
	
	public long getUapuid() {
		return uapuid;
	}

	public void setUapuid(long uapuid) {
		this.uapuid = uapuid;
	}


	public int getFgid() {
		return fgid;
	}
	public void setFgid(int fgid) {
		this.fgid = fgid;
	}
	
	public long getWorkid(){
		return workid;
	}
	
	public void setWorkid(long workid){
		this.workid = workid;
	}

	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getSignature() {
		return signature;
	}
	public void setSignature(String signature) {
		this.signature = signature;
	}
	public int getSysavatar() {
		return sysavatar;
	}
	public void setSysavatar(int sysavatar) {
		this.sysavatar = sysavatar;
	}
	

	  public SearchContract cloneContract(int type){
		  SearchContract o = new SearchContract();
		  Resources res=ApplicationVariable.INSTANCE.applicationContext.getResources(); 
		  switch(type){
			  case 1:
				  o.fgid=this.fgid;
				  
				  o.setUsername(this.getComment()+"(" +res.getString(R.string.friend) + ")");
				break;
			  case 2:
				  o.classid=this.classid;
				  o.setUsername(this.getComment()+"(" +res.getString(R.string.edittxtnull_title) + ")");
				break;
			  case 3:
				  o.deptid=this.deptid;	
				  o.setUsername(this.getComment()+"(" +res.getString(R.string.receive_staff) + ")");
				  break;
				 
		  }
	      o.fid=this.fid;
	      o.uapuid=this.uapuid;
	      o.sysavatar=this.sysavatar;
	      o.signature=this.signature;
	      o.telephone=this.getRelTelePhone();
	        return o;
	    }
	public String getNote() {
		return note;
	}
	public void setNote(String note) {
		this.note = note;
	}

	
	public String getTelephone() {
		return telephone;
	}
	public String getMobilephone() {
		return mobilephone;
	}
	public void setMobilephone(String mobilephone) {
		this.mobilephone = mobilephone;
	}
	public String getDeptid() {
		return deptid;
	}

	public void setDeptid(String deptid) {
		this.deptid = deptid;
	}

	public String getClassid() {
		return classid;
	}

	public void setClassid(String classid) {
		this.classid = classid;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	
	public String getRelTelePhone(){
		if(telephone==null||telephone.equals("")||telephone.equals("null")){
			return mobilephone;
		}
		else return telephone;
	}
	
	public String getComment(){
		if(note==null||note.equals("")||note.equals("null")){
			return username;
		}
		else return note;
	}

	public boolean isChecked() {
		return isChecked;
	}

	public void setChecked(boolean isChecked) {
		this.isChecked = isChecked;
	}

	@Override
	public int describeContents() {
		return 0;
	}
    
	// 把需要写入的数据写入Parcel中,然后框架调用此方法发送给接收端的Activity
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(username);
		dest.writeString(mobilephone);
		dest.writeLong(fid);
		dest.writeLong(uapuid);
		dest.writeInt(isChecked?1:0);
		dest.writeInt(sysavatar);
		
	}
	
	/** 注意：在此Parcelable.Creator 的实例名要为 CREATOR且为public static 否则对象被传出时会抛出异常, 
	 * 外部类反序列化该类时调用此方法
     */

	public static final Parcelable.Creator<SearchContract> CREATOR = new Parcelable.Creator<SearchContract>() {
		@Override
		public SearchContract createFromParcel(Parcel parcel) {
			// 调用私有构造方法
			return new SearchContract(parcel);
		}

		@Override
		public SearchContract[] newArray(int flag) {
			return new SearchContract[flag];
		}
	};
	
	private SearchContract(Parcel parcel) {
		username=parcel.readString();
		mobilephone=parcel.readString();
		fid=parcel.readLong();
		uapuid=parcel.readLong();
		int ischeck=parcel.readInt();
		isChecked=(ischeck==1?true:false);
		sysavatar=parcel.readInt();
	}

}